package com.jp.knowledge.my.business;

import android.text.TextUtils;

import com.jp.knowledge.R;
import com.jp.knowledge.model.AuthInfo;
import com.jp.knowledge.model.UserData;
import com.jp.knowledge.my.activity.CompanyAddressBookActivity;
import com.jp.knowledge.my.activity.InviteMemberActivity;
import com.jp.knowledge.my.activity.InvitePeopleActivity;
import com.jp.knowledge.my.activity.OrganizeActivity;
import com.jp.knowledge.my.activity.OrganizeFranchiseActivity;
import com.jp.knowledge.my.activity.ReviewOrganizeActivity;
import com.jp.knowledge.my.activity.ToBeVipOrganize;
import com.jp.knowledge.my.model.ActiveDataModel;
import com.jp.knowledge.my.model.OptionSelectModel;
import com.jp.knowledge.my.model.OrganizaModel;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gzejia 978862664@qq.com
 */
public class MyMainBusiness {

    public List<OptionSelectModel> getMoreItems() {
        int[] images = {
                R.mipmap.collection,
                R.mipmap.redpackets,
                R.mipmap.archives,
                R.mipmap.scan};
        String[] values = {"收藏",  "钱包", "档案", "扫一扫"};
        List<OptionSelectModel> models = new ArrayList<>();

        for (int i = 0, k = images.length; i < k; i++) {
            OptionSelectModel model = new OptionSelectModel();
            model.mImage = images[i];
            model.mContent = values[i];
            models.add(model);
        }
        return models;
    }

    public List<OptionSelectModel> getAttestationItems(UserData userData) {
        List<OptionSelectModel> models = new ArrayList<>();
        if(userData == null)
            return models;

        int companyType = userData.getOrganizaType();          // 组织类型   1
        int auditStete = userData.getAuditStete();             // 审核状态 1
        int companyManage = userData.getPlatformAdmin();       // 是否是组织管理者 0
        int companyState = userData.getCompanyState();         // 组织状态  0

        List<OrganizaModel> companys = userData.getCompanyList();
        boolean companyAdmin =  false;
        boolean  showOrganza = false;
        int count = 0;
        if(companys!=null)
        for (OrganizaModel company:companys) {
            if(company.getCompanyAdmin()==1){
                companyAdmin=true;
            }
            int state = company.getCompanyState();
            if(state==0){
                count++;
            }

//            if(!showOrganza){//  0未认证，1已认证，2认证中 3，不通过
//                     state = company.getCompanyState();
//                    if(state==0){
//                        showOrganza=true;
//                    }else if(state==1){
//                        AuthInfo info = company.getAuthInfo();
//                        if(info!=null&&!TextUtils.isEmpty(info.getName())){
//                            showOrganza=true;
//                        }
//                    }else if(state==2){
//                        showOrganza=true;
//                    }else if(state==3){
//                        showOrganza=true;
//                    }
//            }
        }

        if(count > 0)
            showOrganza = true;

        if(showOrganza){
            OptionSelectModel   mode = getOptionSelectModel(R.mipmap.authenticationgsi,
                    "认领组织", /*JoinOrgnazitionAcitivity*/OrganizeActivity.class.getName());
            mode.tipCount=count;
            if(count>0)mode.showTip=true;
            models.add(mode);
        }
        if(companyAdmin){
//            models.add(getOptionSelectModel(R.mipmap.departmentmanagement,
//                   "组织架构", DepartmentManagerActivity.class.getName()));

            OptionSelectModel   mode =getOptionSelectModel(R.mipmap.toexamine,
                    (companyType==2)?"审核同学":"加入审核", /*AuditJoinActivity*/ReviewOrganizeActivity.class.getName());
            int num = userData.getAuditNum();
            if(num>0){
                mode.showTip=true;
                mode.tipCount=num;
            }
            models.add(mode);
        }

        if(companys!=null&&companys.size()>0){//有公司 团队通讯录、邀请成员、团队特权出现
            models.add(getOptionSelectModel(R.mipmap.jurisdiction,
                   "通讯录", CompanyAddressBookActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.jurisdiction, "通讯录"
//                    /*(companyType==2)?"班级通讯录":"团队通讯录"*/, CompanyAddressBookActivity.class.getName()));

//            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
//                    "邀请成员", /*ColleagueContactsActivity*/InviteMemberActivity.class.getName()));
            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
                    "邀请成员", InvitePeopleActivity.class.getName()));

//            models.add(getOptionSelectModel(R.mipmap.privilege,
//                    "团队特权", OrganizeFranchiseActivity.class.getName()));
            models.add(getOptionSelectModel(R.mipmap.privilege,
                    "成为VIP企业", ToBeVipOrganize.class.getName()));
        }





//        if(auditStete == 0 && companyManage == 0 && companyState == 0) {
//            models.add(getOptionSelectModel(R.mipmap.certification_company,
//                    "认证"+getOrganizeType(companyType), IdentifyActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
//                    (companyType==2)?"邀请同学":"邀请同事", ColleagueContactsActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.privilege,
//                    /**getOrganizeType(companyType)+*/"团队特权", OrganizeFranchiseActivity.class.getName()));
//        } else if(auditStete == 0 && companyManage == 0 && companyState == 1) {
//            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
//                    "邀请"+(companyType==2?"同学":"同事"), ColleagueContactsActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.privilege,
//                    /*getOrganizeType(companyType)+*/"团队特权", OrganizeFranchiseActivity.class.getName()));
//        } else if(auditStete == 0 && companyManage == 0 && companyState == 2) {
//            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
//                    "邀请"+(companyType==2?"同学":"同事"), ColleagueContactsActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.privilege,
//                    /*getOrganizeType(companyType)+*/"团队特权", OrganizeFranchiseActivity.class.getName()));
//        } else if(auditStete == 0 && companyManage == 1 && companyState == 0) {
//            models.add(getOptionSelectModel(R.mipmap.certification_company,
//                    "认证"+getOrganizeType(companyType), IdentifyActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
//                    (companyType==2)?"邀请同学":"邀请同事", ColleagueContactsActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.privilege,
//                    /*getOrganizeType(companyType)+*/"团队特权", OrganizeFranchiseActivity.class.getName()));
//        } else if(auditStete == 0 && companyManage == 1 && companyState == 1) {
//        } else if(auditStete == 0 && companyManage == 1 && companyState == 2) {
//            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
//                    "邀请"+(companyType==2?"同学":"同事"), ColleagueContactsActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.privilege,
//                    /*(getOrganizeType(companyType)+*/"团队特权", OrganizeFranchiseActivity.class.getName()));
//        } else if(auditStete == 1 && companyManage == 0 && companyState == 0) {
//        } else if(auditStete == 1 && companyManage == 0 && companyState == 1) {
//            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
//                    (companyType==2)?"邀请同学":"邀请同事", ColleagueContactsActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.jurisdiction,
//                    (companyType==2)?"班级通讯录":"团队通讯录", CompanyAddressBookActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.privilege,
//                    /*getOrganizeType(companyType)+*/"团队特权", OrganizeFranchiseActivity.class.getName()));
//        } else if(auditStete == 1 && companyManage == 0 && companyState == 2) {
//        } else if(auditStete == 1 && companyManage == 1 && companyState == 0) {
//        } else if(auditStete == 1 && companyManage == 1 && companyState == 1) {
//            models.add(getOptionSelectModel(R.mipmap.yaoqingtongshi,
//                    (companyType==2)?"邀请同学":"邀请同事", ColleagueContactsActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.jurisdiction,
//                    (companyType==2)?"班级通讯录":"团队通讯录", CompanyAddressBookActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.privilege,
//                    /*getOrganizeType(companyType)+*/"团队特权", OrganizeFranchiseActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.otherorganization,
//                    (companyType==2)?"学院管理":"部门管理", DepartmentManagerActivity.class.getName()));
//            models.add(getOptionSelectModel(R.mipmap.examine,
//                    (companyType==2)?"审核同学":"审核同事", AuditJoinActivity.class.getName()));
//        } else if(auditStete == 1 && companyManage == 1 && companyState == 2) {
//        }

        return models;
    }
    private String getOrganizeType(int companyType){
        if(companyType == 1) {
            return "企业";
        } else if(companyType == 2){
            return "学校";
        } else if(companyType == 3){
            return "众创空间";
        } else if(companyType == 4){
            return "组织";
        } else{
            return "";
        }
    }
    private OptionSelectModel getOptionSelectModel(int image, String content, String value){
        OptionSelectModel model = new OptionSelectModel();
        model.mImage = image;
        model.mContent = content;
        model.mValue = value;
        return model;
    }

    /**
     * 限定用户个人数据类型大小
     *
     */
    public static final int ACTIVE_SIZE = 6;

    /**
     * @param yourIndexList 自定义数据数组，必需保持对应关系
     * @return 用户竞品数据内容
     */
    public List<ActiveDataModel> getActiveData(List<Integer> yourIndexList,UserData userData) {
        List<String> values = new ArrayList<>();
//        if(userData!=null){
//            values.add(String.valueOf(userData.getMessageNum()));
//            values.add(String.valueOf(userData.getFollowNum()));
//            values.add(String.valueOf(userData.getOrderNum()));
//            values.add(String .format("%.2f",userData.getTotalAmount()/100.00));
//            values.add(String.valueOf(userData.getIntegralNum()));
//
//        }else{
//            values.add("0");
//            values.add("0");
//            values.add("0");
//            values.add("0.00");
//            values.add("0");
//        }
        if(userData!=null){
            values.add(String.valueOf(userData.getFollowNum()));
            values.add(String.valueOf(userData.getIntegralNum()));
            values.add(String.valueOf(userData.getOrderNum()));
        }else{
            values.add("0");
            values.add("0");
            values.add("0");
        }
        List<ActiveDataModel> models = new ArrayList<>();

        String[] names = x.app().getResources().getStringArray(R.array.action_data_title);
        int[] icons = new int[]{R.mipmap.minecollection, R.mipmap.knowledgegold, R.mipmap.mineorder};
        for (int i = 0, k = names.length; i < k; i++) {
            ActiveDataModel model = new ActiveDataModel();
            model.mName = names[i];
            model.mIcon = icons[i];
            model.value=values.get(i);
            models.add(model);
        }
        return models;
    }
}
